<template>
	<view>
		<view>
			<u-tabs :list="list" name="title" :is-scroll="true" :current="current" @change="change" ></u-tabs>
		</view>
		<view class="content">
			<view class="boutique">
				<view class="boutique-title">
					<view class="boutique-content">
						<view class="small-content" v-for="(item,index) in courseData" @click="goDetail(item.courseId)" :key="index">
							<image :src="item.bannerFileUrl" class="class-img"></image>
							<view class="bottom-title">
								{{item.courseTitle}}
							</view>
							<view class="bottom-tip">
								<view class="free-word">
									免费
								</view>
								<view class="small-live">
									<image src="../../static/images/live.png" mode="widthFix"></image>
									{{item.learningNum}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {getPost,getGet} from "../../api/index.js"
	export default {
		data() {
			return {
				list: [],
				current: 0,
				courseData:[]
			};
		},
		methods: {
			change(index) {
				this.current = index;
				// console.log(index)
				console.log(this.list[0].id)
				getGet(`/pc/course/search/keyword/?subjectId=${this.list[index].id}`).then(res=>{
					console.log(res)
					this.courseData=res.data.courseList
				})
			},
			goDetail(data){
				// console.log(data)
				uni.navigateTo({
					url:`/pages/detail/detail?id=${data}`
				})
			}
		},
		onLoad() {
			let data=JSON.stringify({"type": "free","pageNum": 1,"pageSize": 10,"enable":1})
			getPost("/weChat/applet/subject/list",data,{header:{"Content-Type":"application/json"}}).then(res=>{
				console.log(res.data.rows)
				res.data.rows.forEach((item,index)=>{
						this.list.push({
							title: item.subjectTitle,
							id:item.subjectId
						})
				})
				getGet(`/pc/course/search/keyword/?subjectId=${this.list[0].id}`).then(res=>{
					console.log(res.data.courseList)
					this.courseData=res.data.courseList
				})
				
			})
			
		}
	}
</script>

<style lang="less" scoped>
	.small-content{
		display: flex;
	}
	.boutique-content{
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
	}
	.small-live{
		image{
			width: 20rpx;
			margin-right: 10rpx;
		}
	}
	.class-img{
		width: 340rpx;
		height: 170rpx;
	}
	.bottom-title{
		height: 34px;
	}
	.small-content{
		padding: 10rpx 0;
		width: 340rpx;
		display: flex;
		flex-direction: column;
	}
	.bottom-tip{
		display: flex;
		justify-content: space-between;
	}
	.free-word{
		color: #00cf8c;
	}
	.top-tips{
		font-size: 30rpx;
		font-weight: bold;
	}
	.top-title{
		padding: 20rpx 0;
		display: flex;
		justify-content: space-between;
	}
	.content{
		padding:30rpx;
	}
	.bottom-tip{
		margin-top: 10rpx;
	}
</style>
